(function () {
    var template = `
    {% if(data.id){ %}
        <div class="game">
            <div class="game-content">
                <!--游戏图标-->
                <a href="/game/detail/{% data.id %}" target="_blank">
                     <img data-original="{% data.img %}">
                </a>
                <!--游戏信息-->
                <div class="game-detail">
                    <div class="game-title">
                        <h3>
                            <span class="game-cate">{% data.cate_id %}</span>
                            <a href="/game/detail/{% data.id %}" target="_blank">{% data.name %}</a>
                        </h3>      
                    </div> 
                    <!--tag-->
                    {% if( data.tags ) { %}
                        <div class="game-tag">
                            {% for(var i = 0; i < data.tags.length; i++ ) { %}
                                <span> {% data.tags[i] %} </span>
                            {% } %}
                         </div>
                    {% } %}
                </div>
                <!--如果有需要关注功能-->
                <div class="attention">
                    <span class="iconfont icon-guanzhu"></span>
                    <span>{% data.nums %}人关注</span>
                </div>
            </div>
            <!--大图-->
            <a class="pic" href="/game/detail/{% data.id %}" target="_blank">
                <img data-original="{% data.xc_img %}">
            </a>
            <!--详情介绍-->
            {% if( data.short_intro ) { %}
               <p class="game-intro ellipse">{% data.short_intro %}</p>
            {% } %}
        </div>
    {% }else{ %}
        <div class="tg game">
            <div class="game-content">
                <h3 class="tg-title"><span>广告</span>{% data.title %}</h3>
            </div>
            <a class="pic" href="{% data.url %}"  target="_blank">
                <img data-original="{% data.img %}" alt="{% data.title %}">
            </a>
        </div>
    {% } %}`;

    var swiper = new Swiper('.banner', {
        autoplay: 5000,
        loop: true,
        pagination: '.swiper-pagination',
        paginationClickable: true,
        onSlideChangeEnd: function( swiper ){
            $("img").lazyload({
                effect: "fadeIn",
                effectspeed: 1500
            });
        }
    });

    var loadIndexList = new LoadData({
        btn: '#getMoreBtn',
        lists: '#gameIndexList',
        listType: 'game',
        url: '/welcome/ajax_index_list',
        page: 2,
        template: template,
        method: 'append',
        loadingAnim: true,
        loadingAnimDom: '.loading-container',
        handleFn: {
            'cate_id': utils.setDataItem.bind(utils),
            'tags': utils.setDataItem.bind(utils)
        },
        afterRender: function () {
            $("img").lazyload({
                effect: "fadeIn",
                effectspeed: 1500
            });
        }
    });

})();